import Menu, OutPut, InPut, Refresh, Search, Modify, Delete
from testinput import test_if_int2

read = open("information.txt", encoding="UTF-8")
# 读取文件中的数据并放入列表
main_list = list()
for line in read:
    main_list.append(line.split(" "))
read.close()
while True:
    Menu.PrintMenu()
    num, judge = test_if_int2.test_if_int_function(input("请选择:>"))
    if judge:
        if num == 1:
            # 显示成员信息
            OutPut.OutPutFunction(main_list)
        elif num == 2:
            # 录入成员信息
            main_list = InPut.InPutFunction(main_list)
        elif num == 3:
            # 用名字查找成员
            OutPut.OutPutFunctionSmall(main_list[Search.SearchFunction(main_list)])
        elif num == 4:
            # 修改宿舍成员信息
            index = Search.SearchFunction(main_list)
            if index != -1:
                main_list = Modify.ModifyFunction(main_list, index)
        elif num == 5:
            # 删除成员信息
            main_list = Delete.DeleteFunction(input("请输入你要删除的成员的名字:>"))
        elif num == 0:
            # 退出程序
            break
        else:
            # 输入错误
            print("选项不存在")
        # 将整个文件清空并录入修改后的数据
        Refresh.RefreshFunction(main_list)
